{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'one': 2}\n",
      "<class 'abc.ABCMeta'>\n"
     ]
    }
   ],
   "source": [
    "## 不建议直接继承 list 和 dict\n",
    "\n",
    "from collections import UserDict\n",
    "class MyDict(UserDict):\n",
    "    def __setitem__(self, key, value):\n",
    "        super().__setitem__(key, value * 2)\n",
    "        \n",
    "my_dict = MyDict(one=1)\n",
    "print(my_dict)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{}\n"
     ]
    }
   ],
   "source": [
    "## defaultdict\n",
    "from collections import defaultdict\n",
    "\n",
    "my_dict = defaultdict(dict)\n",
    "my_value = my_dict['bobby']\n",
    "print(my_value)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
